home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 001 / serialde / BlockSpec next >
Text File  |  1994-08-17  |  17KB  |  482 lines

  1. Block Driver Specification
  2. --------------------------
  3.  
  4. Hugo Fiennes, Rev 10a, 17th August 1994
  5.  
  6. Contact me on 0749 670058 (altman@cryton.demon.co.uk, fidonet 2:255/102.0)
  7. for information about the latest version of the spec.
  8.  
  9. Aim
  10. ---
  11.  
  12. To provide a standard way for applications to access serial devices. Any
  13. application supporting block drivers can be used with many serial devices,
  14. with no modification required to the application code - and it's easier
  15. to use than the serial SWIs anyway!
  16.  
  17. Info
  18. ----
  19.  
  20. This standard is public domain. The drivers supplied are freely distributable
  21. but ⌐ 1994 Hugo Fiennes of The Serial Port. If you intend to use the block
  22. drivers, please distribute the whole block driver package (inc sample source,
  23. this file, and the complete !SerialDev application) with your program,
  24. making sure that you are distributing the latest version (available from
  25. The World of Cryton BBS, Arcade BBS, and ftp.demon.co.uk in the /pub/archimedes
  26. directory).
  27.  
  28. An application called !SerialDev holds the drivers - in your application !Run
  29. sequence you should check to see if <SerialDev$Path> is set, and if not, set
  30. it to your application directory, inside which is Modules.Internal at least,
  31. for your application to default to the internal port.
  32.  
  33. Eventually the idea is to have !SerialDev hold an application that handles
  34. the installation in a 'pretty way' - eg dragging new drivers to a window to
  35. install them, this would check to see if the driver was a later version of an
  36. existing driver and if so replace the old one, otherwise it would install the
  37. driver. Maybe this application could look a bit like ArtWorks !FontInst.
  38. Hint, hint, somebody write one...
  39.  
  40. The drivers each have their own directory just in case, possibly extensions
  41. with !Run files, modules, etc relating to the driver could be stored there.
  42. Of course, drivers know their own name and could load files into RMA on
  43. initialisation now and cause no problems.
  44.  
  45. ARCterm 7 1.44 and later use drivers of this specification. In this
  46. archive I have included some other drivers, documented below.
  47. Other programs that support block drivers are: Binkleyterm (2.11+),
  48. Hearsay 2 (2.17+), ARCfax (1.06+), ARCbbs (1.63+), RISCbbs (1.02+),
  49. Netway.
  50.  
  51. C headers have been provided for C programmers. BASIC/Assembler people
  52. should have no problems working it out either - a small application,
  53. 'Example' is provided which will work with any block driver module to
  54. provide a very simple terminal program.
  55.  
  56. REVISION 4 : Added 'wont empty' and 'dont overlay io' flags for pipes and
  57.              (unfixed) RO3.10 serial ports.
  58.  
  59. REVISION 5 : Intialise can now return an error string.
  60.  
  61. REVISION 6 : More information on calling initialise.
  62.  
  63. REVISION 7 : Pipe drivers now support 'peek byte' - return next byte in
  64.              buffer without removing it.
  65.  
  66. REVISION 8 : Internal port with PC cable now works with DCD low (bit 1
  67.              on SerialOp 0 now set). OSBYTE 152 used for peek byte
  68.              (for some reason the proper legal method doesn't work well).
  69.  
  70. REVISION 9 : All drivers must now store R14 on the stack so they can
  71.              be called from supervisor mode.
  72.  
  73. REVISION 10: Basically this release just tidied the internal driver for
  74.              RiscPC use - hitting the metal isn't required anymore to
  75.              set high rates, so it isn't done. Still needed on A5000,
  76.              A3010, A3020, A4000 & A4 though.
  77.  
  78.              Inquiry initialise (see below) added for JP :-) This is
  79.              implemented in Internal, SP_Dual and Pipe drivers. It's
  80.              only really necessary in the Internal (sets baud tables)
  81.              and the SP_Dual (counts installed ports) drivers.
  82.  
  83. REVISION 10a:"I must not release software without testing it" :-)
  84.              A little buglet in the SP_Dual drivers was pointed out to
  85.              me, "they don't work!". This has now been fixed. Drivers
  86.              should now also preserve the PSR (Internal, Dummy, Pipe,
  87.              and SP_Dual do) just in case.
  88.  
  89. Internal driver
  90. ---------------
  91.  
  92. There are two version of this: Internal and InternalPC - the PC version
  93. expects a standard PC serial cable, which will only work properly on A5000
  94. or later machines (some early A5000s might have problems too).
  95.  
  96. Needs RO3.1 for block operations.
  97.  
  98. On a 'new hardware' machine (ie A5000 or later) will support 38400, 57600,
  99. 115200 automatically. Remember that these rates may well not be reliable
  100. due to the lack of FIFO on the serial chip. These rates are acheived by
  101. writing directly to the serial chip, which is definitely not Acorn-approved.
  102. Beware!
  103.  
  104. On RiscPCs all rates to 115200 should be perfectly reliable as the hardware
  105. now includes a FIFO.
  106.  
  107. Cables - the Acorn wiring for a modem is this:
  108.  
  109.    Acorn 9w female               Modem 25w male
  110.    ---------------               --------------
  111.        1-4-8                           20
  112.          2                              3
  113.          3                              2
  114.          5                              7
  115.          6                              5
  116.          7                              4
  117.          9                              8
  118.  
  119. And the PC wiring is this:
  120.  
  121.    Acorn 9w female               Modem 25w male
  122.    ---------------               --------------
  123.          1                              8
  124.          2                              3
  125.          3                              2
  126.          4                             20
  127.          5                              7
  128.          6                              6 (not usually used much)
  129.          7                              4
  130.          8                              5
  131.          9                             22 (not usually used much)
  132.  
  133. Serial Port Dual Serial
  134. -----------------------
  135.  
  136. Again, there are 2 versions: SP_Dual and SP_DualPC, the PC version expects
  137. a standard PC serial cable.
  138.  
  139. Since release 9, the Xon/Xoff flags are cleared every time flow control
  140. is changed to stop things sticking if an Xoff has been received.
  141.  
  142. PipeA and PipeB
  143. ---------------
  144.  
  145. This will autoload the ARCbbs_Pipes module (contained in the PipeA directory)
  146. if necessary.
  147.  
  148. The idea is, you open a port (0-15) on pipeA and data sent appears in the
  149. input of the corresponding port on pipeB (and vice-versa). DTR at one end
  150. is translated to DCD at the other (ditto for RTS-CTS). In this way, any
  151. application which supports the block driver spec can talk to another, for
  152. example, with ARCbbs and the ARCterm modem server on the same machine,
  153. some ARCbbs ports could be given over to network access via the modem
  154. server.
  155.  
  156. The pipes use the flag 'wont empty' as you can't wait for the pipe to
  157. 'finish sending' as the other end of the pipe may be waiting for the same
  158. thing (unlike a serial port, where the data will go away eventually).
  159.  
  160. The pipes are 2k long in each direction.
  161.  
  162. Acorn Telnet (Needs Acorn's TCP/IP protocol suite)
  163. ------------
  164. *Note! Does not store R14_SVC
  165.  
  166. This is only in testing, but is supplied as it might be useful. The coding
  167. is possibly quite inefficient, but it works. You require !Internet and 
  168. !Telnet to have been run before trying to use the driver. It will prompt
  169. for a host name - type one, or an internet address. You can add ',xx'
  170. where xx is the port number to telnet into. DCD as reported by modem
  171. status will go high when a sucessful connection is made. Dropping DTR
  172. then raising it again will clear any current call.
  173.  
  174. Known bugs: You can't have multiple sessions - if you load another emulator
  175. and run telnet the port_claim message will stop the first one - possibly a
  176. 'dynamic' port number (returned by init?) should be put into the spec to
  177. cater for things like this.
  178.  
  179.  
  180. Dummy (/dev/null)
  181. -----
  182.  
  183. This is a dummy driver, for when you want somewhere to trash data. It
  184. always shows CTS, DSR and DCD, and will completely ignore any data you
  185. send to it. It never has any data to give you.
  186.  
  187. II_Dual driver
  188. --------------
  189. *Note! Does not store R14_SVC
  190.  
  191. This is a temporary stop-gap until v3.xx software is available for the II
  192. card. The port number you specify is the II port number -1, ie II port 3
  193. would be specified as port 2. If you want to use the internal port while
  194. using II ports, you need the Internal2 driver. Both of these drivers
  195. rely on the poll entry being called directly after each wimp poll, to set
  196. the current port.
  197.  
  198. Econet driver (not supplied with this release)
  199. -------------
  200.  
  201. This works with ARCterm's new 16-line modem server to allow remote serial
  202. access. To support connection, etc, it has 3 special functions:
  203.  
  204. Connect (function code 128)
  205.   r1=handle/net/station (handle in bits 16-23,net in bits 8-15, station in 0-7)
  206.   r2-> password, null terminated
  207.  
  208.   Tries to set up a connection with the modem server. Returns 0 for success,
  209.   1 for no reply, 2 for already connected, or a pointer to an error block if
  210.   r0 is 'big' on return.
  211.  
  212. Disconnect (function code 129)
  213.   Disconnects from the modem server.
  214.  
  215. Scan for modem servers (function code 130)
  216.   r1=buffer to fill of format:
  217.      0    station
  218.      1    net
  219.      2    handle
  220.      3    modem driver number as defined in the modem server config file
  221.      4-63 modem ID string (null terminated)
  222.   r2=max number of entries table can handle
  223.  
  224. -------------------------------------------------------------------------------
  225. Driver layout
  226. -------------------------------------------------------------------------------
  227.  
  228. 0x000 Entry point to call routines
  229.  
  230.       In:  r0=function code
  231.            r1-r3=data
  232.  
  233.       Out: r0=result
  234.  
  235.       NOTE! CHANGE IN REVISION 9!
  236.       |
  237.       | This entry point can be called in EITHER user or supervisor mode, so
  238.       | R14 should always be pushed on the stack (STMFD R13!,{R14}) and be used
  239.       | to return from the driver so that r14_svc is preserved if the driver is
  240.       | called when in supervisor mode.
  241.       |
  242.  
  243.       r0-r3 can be corrupted, r4-r12 should be preserved. r14 contains the
  244.       return address
  245.  
  246.       Callers note that r13 should point to a full, descending stack
  247.       with a decent amount of space free on it.
  248.  
  249.       Example handler code follows:
  250.  
  251.       entry
  252.             STMFD R13!,{R14}
  253.             CMP   R0,#((endoftable-table)/4)
  254.             ADDCC PC,PC,R0,LSL#2
  255.             LDMFD R13!,{PC}
  256.  
  257.       table
  258.             B     func_0
  259.             B     func_1
  260.       endtable
  261.  
  262. 0x080 Driver information string (31 bytes max, 0 terminated)
  263. 0x0A0 Manufacturer information string (31 bytes max, 0 terminated)
  264. 0x0C0 Version number (top 16 bits major, low 16 bits minor)
  265. 0x0C4 Driver flags
  266.  
  267.       0x00000001 - More than one port availiable
  268.       0x00000002 - Supports split rates
  269.       0x00000004 - Has >1 byte hardware FIFO
  270.       0x00000008 - Can use Set control lines to generate a break
  271.       0x00000010 - Requires polling (by function 19)
  272.       0x00000020 - Won't empty (is a shared buffer)
  273.       0x00000040 - Supports block get/put operations
  274.       0x00000080 - Prefer not to overlap serial IO and disk IO
  275.       0x00000100 - Supports inquiry initialise
  276.  
  277.       0xdd...... - Top byte is highest port number supported (numbered from 0)
  278. 0x0C8 Driver number. This is allocated by me, and always has the lowest byte
  279.       as 0. The purpose of the driver number is for the Device_Claim protocol:
  280.       when a serial port is specified, the port number is used to specify
  281.       which port is to be claimed/released. The internal port is port 0 and
  282.       driver number 0. To make the port number to use you add the sub-port
  283.       number and the driver number together. eg, say the II dual card was
  284.       driver number 1 (0x00000100) and you wanted to claim port 5, you
  285.       would use the port number 0x00000105. This is unique and hopefully
  286.       would cause no problems.
  287.  
  288.       PORT NUMBERS PASSED TO BLOCK DRIVERS ARE THE LOWER 8 BITS ONLY: THEY DO
  289.       NOT INCLUDE THE DRIVER NUMBER.
  290.  
  291.       Currently allocated driver numbers:
  292.  
  293.         0 - Internal serial
  294.         1 - II dual serial
  295.         2 - Serial port dual serial
  296.         3 - Internal serial with PC cable
  297.         4 - Brainsoft Multipod (Kelvin Hill, #179 on Cryton)
  298.         5 - Acorn telnet interface
  299.         6 - Serial port dual serial with PC cable
  300.  
  301.       100 - Remote econet driver
  302.       128 - Virtual pipe (end A)
  303.       129 - Virtual pipe (end B)
  304.  
  305. 0x0CC - 0x0FF reserved
  306.  
  307. 0x100 Supported speed table. One word per speed, terminated with a null word.
  308.  
  309. 0x180-> driver code.
  310.  
  311. Function codes
  312. --------------
  313.  
  314. r0=0  Put byte
  315.       --------
  316.       r1=port number
  317.       r2=byte to send
  318.  
  319.       Returns with r0=-1 if byte not inserted, r0=0 if byte inserted into
  320.       TX queue.
  321.  
  322. r0=1  Get byte
  323.       --------
  324.       r1=port number
  325.  
  326.       Returns with r0=-1 if no byte availiable, r0=byte if a byte was removed.
  327.  
  328. r0=2  Put block
  329.       ---------
  330.       r1=port number
  331.       r2=pointer to block
  332.       r3=number of bytes to try and insert
  333.  
  334.       Returns with r0=number of bytes sucessfully inserted.
  335.  
  336. r0=3  Get block
  337.       ---------
  338.       r1=port number
  339.       r2=pointer to block
  340.       r3=maximum number of bytes to put into buffer
  341.  
  342.       Returns with r0=number of bytes put in buffer.
  343.  
  344. r0=4  Check TX buffer
  345.       ---------------
  346.       r1=port number
  347.  
  348.       Returns with r0=number of bytes free in TX buffer
  349.  
  350. r0=5  Check RX buffer
  351.       ---------------
  352.       r1=port number
  353.  
  354.       Returns with r0=number of bytes used in RX buffer
  355.  
  356. r0=6  Flush TX buffer (and hardware FIFO if applicable)
  357.       ---------------
  358.       r1=port number
  359.  
  360. r0=7  Flush RX buffer (and hardware FIFO if applicable)
  361.       ---------------
  362.       r1=port number
  363.  
  364. r0=8  Control lines
  365.       -------------
  366.       r1=port number
  367.       r2=-1 to read or new settings
  368.  
  369.       Returns r0=control line settings
  370.  
  371.       b0=DTR
  372.       b1=RTS
  373.       b2=If set, set TX data active (ie break state)
  374.  
  375. r0=9  Read modem control lines
  376.       ------------------------
  377.       r1=port number
  378.  
  379.       Returns r0=control line status
  380.  
  381.       b0=CTS
  382.       b1=DSR
  383.       b2=RI
  384.       b3=DCD
  385.  
  386. r0=10 Read RX errors
  387.       --------------
  388.       r1=port number
  389.  
  390.       Returns r0=bitset of errors seen since last read RX errors.
  391.  
  392.       b0=Overrun error
  393.       b1=Parity error
  394.       b2=Framing error
  395.       b3=Break received
  396.  
  397. r0=11 Send break
  398.       ----------
  399.       r1=port number
  400.       r2=break time (in centiseconds)
  401.  
  402.       This does not return until the break has been sent - although some
  403.       serial ports could multitask when sending a break, the internal port
  404.       can't. Check the driver flags to see if you can use a multitasking
  405.       break before using this call.
  406.  
  407. r0=12 Examine byte (like Get byte but leaves it in the buffer)
  408.       ------------
  409.       r1=port number
  410.  
  411.       Returns with r0=-1 if no byte availiable, r0=byte if a byte was
  412.       returned.
  413.  
  414. r0=13 TX Speed
  415.       --------
  416.       r1=port number
  417.       r2=speed to set or -1 to read
  418.  
  419.       Returns with r0=speed.
  420.  
  421. r0=14 RX Speed
  422.       --------
  423.       r1=port number
  424.       r2=speed to set or -1 to read
  425.  
  426.       Returns with r0=speed.
  427.  
  428. r0=15 Set word format
  429.       ---------------
  430.       r1=port number
  431.       r2=word format to set or -1 to read
  432.  
  433.       Returns with r0=word format.
  434.  
  435. r0=16 Set flow control
  436.       ----------------
  437.       r1=port number
  438.       r2=flow control method to set or -1 to read
  439.  
  440.       Returns with r0=method
  441.  
  442.       0=no flow control
  443.       1=hardware
  444.       2=xon/xoff
  445.       3=both
  446.  
  447. r0=17 Initialise driver
  448.       -----------------
  449.       r1=port number
  450.       r2=parameter string (optional)
  451.  
  452.       r2 optionally points to a null terminated string which can specify
  453.       device options.
  454.  
  455.       Returns with r0 pointing to error string if
  456.       initialisation unsucessful, otherwise r0=0.
  457.  
  458.       NOTE! Do not read the baud rate tables or driver flags UNTIL AFTER
  459.       the intialise driver entry has been called. This allows for drivers
  460.       to configure themselves to the available hardware and adjust the
  461.       services offered accordingly.
  462.  
  463.       Release 10: There is now a flag, 'supports inquiry initialise' (see
  464.       above) which allows you to call the initialise entry with r1=-1,
  465.       which will not touch any hardware, just set all the baud tables,
  466.       driver flags, and count the number of ports installed (if necessary),
  467.       so you can read them and set up menus, etc.
  468.  
  469. r0=18 Close down driver
  470.       -----------------
  471.       r1=port number
  472.  
  473. r0=19 Poll driver
  474.       -----------
  475.       r1=port number
  476.  
  477.       This should be called regularly (eg in a polling loop) for the driver
  478.       to perform polling tasks - eg the econet driver needs to check internal
  479.       buffers and poll econet protocol tasks. Polls can be as infrequent as
  480.       three or four times a second : if a driver needs polling more often
  481.       than that, it should install a module and hook onto a vector somewhere.
  482.